package com.lanou.utp.controller;

import com.lanou.utp.entity.Base;
import com.lanou.utp.service.BaseInfoService;
import com.lanou.utp.entity.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author MaQingYun
 */
@Api("基地信息管理")
@RestController
public class BaseInfoController {

    @Resource
    private BaseInfoService baseInfoService;

    @ApiOperation("获取基地信息列表")
    @GetMapping("/bases")
    public ResponseData getBaseList(Integer page) {
        return this.baseInfoService.getBaseList(page);
    }

    @ApiOperation("添加基地信息")
    @PostMapping("/base")
    public ResponseData addBaseInfo(@RequestBody @Validated(Base.addBaseInfo.class) Base baseinfo) {
        this.baseInfoService.addBaseInfo(baseinfo);
        return new ResponseData("ok");
    }

    @ApiOperation("修改基地信息")
    @PutMapping("/base")
    public ResponseData updateBaseInfo(@RequestBody @Validated(Base.addBaseInfo.class) Base baseinfo) {
        this.baseInfoService.updateBaseInfo(baseinfo);
        return new ResponseData("ok");
    }


    @ApiOperation("/删除单条基地信息")
    @DeleteMapping("/base/{id}")
    public ResponseData deleteByBaseId(@PathVariable("id") Long id){
        this.baseInfoService.deleteByBaseId(id);
        return new ResponseData("ok");
    }

    @ApiOperation("/批量删除基地信息")
    @DeleteMapping("/bases/{list}")
    public ResponseData deleteBases(@PathVariable("list") List list){
        this.baseInfoService.deleteBases(list);
        return new ResponseData("ok");
    }

}
